package cn.zhang.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@Slf4j
public class ChatClientV2Controller {

    @Resource
    private ChatModel chatModel;

    @Resource
    private ChatClient chatClient;


    @GetMapping(value = "/chatClientv2/dochat")
    public String doChat(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        return chatClient.prompt().user(msg).call().content();
    }

    @GetMapping(value = "/chatClientv2/stream")
    public Flux<String> stream(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        Flux<String> stream = chatModel.stream(msg);
        return stream;
    }

}
